package com.lc.hot100.lc198;

public class Main {
	public static void main(String[] args) {
		
	}
}

class Solution {
    public int rob(int[] nums) {
        
    	int n = nums.length;
    	
    	int[] f = new int[n];
    	f[0] = nums[0];
    	if (n == 1) {
    		return f[0];
    	}
    	int res = 0;
    	f[1] = Math.max(f[0], nums[1]);
    	res = Math.max(res, f[1]);
    	for (int i = 2; i < n; i ++) {
    		f[i] = Math.max(f[i - 1], f[i - 2] + nums[i]);
    		res = Math.max(res, f[i]);
    	}
    	return res;
    }
}
